#ifndef CMDLTREENODE_H
#define CMDLTREENODE_H

#include "CEntity.h"
#include <vector>
#include <QTreeWidgetItem>

class CMdlTreeView;

using namespace csmodel;

struct CMdlTreeTraits
{
  int maxRight;
  CMdlTreeTraits() : maxRight(0) {}
};

class CMdlTreeNode
{
    std::vector< CMdlTreeNode >     nodes;
    CMdlTreeView *                  tree;
public:
    CMdlTreeNode( CMdlTreeView * tree, CEntity * e, CMdlTreeNode * owner = 0 );
    CMdlTreeNode();
    CMdlTreeNode( const CMdlTreeNode & src ) { *this = src; }
    CMdlTreeNode & operator = ( const CMdlTreeNode & src );

    CMdlTreeNode * PushToMap( std::vector< CMdlTreeNode* > & map, CEntity * e );

    bool operator < ( const CMdlTreeNode & x ) const;

    void Update( CMdlTreeTraits * treeTraits );

    CMdlTreeNode * FindNodeOfEntity( CEntity * e );

    CMdlTreeNode * FindChildNodeOfEntity( CEntity * e );

    bool GetCollapsed() const;
    bool GetExpanded() const;
    bool GetHasChildren() const;
    int  GetLevel() const;

    void Expand();
    void Collapse();
    void ChangeState();

    CEntity *       Entity;
    int             Index;
    bool            Collapsed;// = { read=GetCollapsed };
    bool            Expanded;// = { read=GetExpanded };
    unsigned int    ChildNodesCount;// = { read=childNodesCount };
    QString         Text;// = { read=text };
    bool            HasChildren;// = { read=GetHasChildren };
    CMdlTreeNode *  Owner;// = { read=owner };
    CMdlTreeNode *  PrevSibling;// = { read=prevSibling };
    CMdlTreeNode *  NextSibling;// = { read=nextSibling };
    int             Level;// = { read=GetLevel };

    QTreeWidgetItem * baseTreeWidgetItem;
};

#endif // CMDLTREENODE_H
